﻿using Projet_IMA.Base;
using Projet_IMA.Habillage.Material;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Projet_IMA.Object3D
{
    public class Triangle : Object3DBase
    {
        private V3 A;
        private V3 B;
        private V3 C;


        public Triangle(V3 A, V3 B, V3 C, MaterialBase material, float pas)
            : base(pas, material)
        {
            this.A = A;
            this.B = B;
            this.C = C;
        }

        protected override void MakeCache()
        {
            List<V3> points = new List<V3>((int)(1 / pas * 1 / pas / 2));
            List<Color> c = new List<Color>((int)(1 / pas * 1 / pas / 2));
            V3 AB = new V3(B - A);
            V3 AC = new V3(C - A);
            V3 point, normal = AB ^ AC;
            normal.Normalize();

            for (float u = 0; u < 1; u += pas)
                for (float v = 0; v < 1; v += pas)
                {
                    if (u + v > 1) break;

                    point = A + u * AB + v * AC;
                    points.Add(point);
                    c.Add(material.GetColor(u, v, normal, AB, AC));
                }

            this.cache.Reset();
            cache.load(points, c);
        }

        public override V3 getNormalOfPoint(V3 point)
        {
            return null;
        }
    }
}
